﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyFrame
{
    /// <summary>
    /// Bll层基类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class BaseBll<T> where T : BaseModel,new()
    {
        protected BaseDal<T> baseDal;

        public BaseBll()
        {
            //todo：需要在派生类中实例化baseDal
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="Id">主键</param>
        /// <returns></returns>
        public T Get(string Id)
        {
            return baseDal.Get(Id);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回的是主键</returns>
        public string Add(T model)
        {
            model.Id = Guid.NewGuid().ToString();
           return baseDal.Add(model);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id">主键</param>
        public void Delete(string Id)
        {
            baseDal.Delete(Id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        public void Update(T model)
        {
            baseDal.Update(model);
        }

        /// <summary>
        /// 获取全部
        /// </summary>
        /// <returns></returns>
        public List<T> GetAll()
        {
            return baseDal.GetAll();
        }

    }
}
